<?php
error_reporting('IGNORE_REPEATED_ERRORS');
?>
<html>
<HEAD>
</HEAD>
<B>DRAFT REPORT</B><BR>
<?php



mysql_connect("localhost", "root", "") or
    die("Could not connect: " . mysql_error());
mysql_select_db("QA");



$start_date = $_GET["start_date"];
$end_date = $_GET["end_date"];


if (strlen($start_date)<1) {
	$result = mysql_query("SELECT MIN(CALL_DATE) FROM QA.Caller");
	$row = mysql_fetch_array($result, MYSQL_BOTH);
	$start_date = $row[0];
}

if (strlen($end_date)<1) {
	$result = mysql_query("SELECT MAX(CALL_DATE) FROM QA.Caller");
	$row = mysql_fetch_array($result, MYSQL_BOTH);
	$end_date = $row[0];
}
echo "<BR>This report is for the date range ".$start_date." through ".$end_date." inclusively.<BR>";

$qstring = "select QA.Agencies.Agency_Description, QA.Taxonomies.Taxonomy_Description, count(QA.Agencies.Agency_Description) as Count ";
$qstring = $qstring."FROM QA.Agencies, QA.Taxonomies, QA.Caller, QA.AgencyFeedback  ";
$qstring = $qstring."WHERE QA.Agencies.Reference_Number=QA.AgencyFeedback.Agency AND QA.Taxonomies.Reference_Number=QA.AgencyFeedback.Taxonomy AND QA.Caller.Reference_Number=QA.AgencyFeedback.Caller_Reference AND QA.Caller.Call_Date BETWEEN \"".$start_date."\" AND \"".$end_date."\"";
$qstring = $qstring."GROUP BY QA.Agencies.Agency_Description Order BY Count DESC";
$result = mysql_query($qstring);


echo "<TABLE border=1><TR><TD colspan=3 align=center width=100%>Top Agency Activity Report between $start_date and $end_date</TD></TR>";
echo "<TR><TD>Agency</TD><TD>Taxonomy</TD><TD>Count</TD></TR>";

$bgcolor_top = "00DD00";
$bgcolor_other = "00FFDD";
$bgcolor_none = "FFFFFF";
$bgcolor_count = 10;
$bgcolor = $bgcolor_top;
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
	if( $bgcolor_count == 0 ) { $bgcolor = $bgcolor_other;}
	$bgcolor_count = $bgcolor_count - 1;
	if($row[2]==1) {$bgcolor = $bgcolor_none;}
	echo "<TR bgcolor=$bgcolor><TD>".$row[0]."</TD><TD>".$row[1]."</TD><TD>".$row[2]."</TD></TR>";
}

mysql_free_result($result);

echo "<TR><TD colspan=3 align=center width=100%> End </TD></TR></TABLE>";



echo "<BR>";


?>







<br>
</body>
</html>
